package system_sms_service

import (
	"gitee.com/Luna-CY/Golang-Project-Template/internal/context"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/errors"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/interface/service"
	"gitee.com/Luna-CY/Golang-Project-Template/internal/logger"
	"gitee.com/Luna-CY/Golang-Project-Template/model"
)

func (cls *Sms) UpdateLog(ctx context.Context, log *model.SystemSmsLog, fields ...service.SystemSmsLogField) errors.Error {
	if nil == log {
		logger.SugarLogger(logger.WithRequestId(ctx), logger.WithStack()).Errorf("ISS_MS.S_MS.UL_OG.132535 异常的传入参数")

		return errors.ErrorServerInternalError("ISS_MS.S_MS.UL_OG.152542", "异常的传入参数")
	}

	for _, field := range fields {
		if err := field(log); nil != err {
			return err.Relation(errors.ErrorServerInternalError("ISS_MS.S_MS.UL_OG.202729", "应用选项失败"))
		}
	}

	if err := cls.smsLog.SaveSystemSmsLog(ctx, log); nil != err {
		return err.Relation(errors.ErrorServerInternalError("ISS_MS.S_MS.UL_OG.232553", "更新短信日志失败"))
	}

	return nil
}
